package ch05.home;

class Exercise5_07 {
	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("USAGE: java Exercise5_07 3120");
			System.exit(0);
		}
		
		int money = Integer.parseInt(args[0]);
		System.out.println("money=" + money);
		
		int[] coinUnit = { 500, 100, 50, 10 };
		int[] coin = { 5, 5, 5, 5 };
		for (int i = 0; i < coinUnit.length; i++) {
			int coinNum = 0;
			
			//<1
			coinNum = money/coinUnit[i];
			if (coin[i] >= coinNum)	coin[i] -= coinNum;
			else {
				coinNum = coin[i];
				coin[i] = 0;
			}
			money -= coinNum * coinUnit[i];
			//1>
			
			System.out.println(coinUnit[i] + "원: " + coinNum);
		}
		
		if (money > 0) {
			System.out.println("short change.");
			System.exit(0);
		}
		System.out.println("count remain coin.");
		for (int i = 0; i < coinUnit.length; i++) 
			System.out.println(coinUnit[i] + "원:" + coin[i]);
	}
}
/*
money=3170
500원: 5
100원: 5
50원: 3
10원: 2
count remain coin.
500원:0
100원:0
50원:2
10원:3
*/